#ifndef __UART_UPGRADE_H__
#define __UART_UPGRADE_H__

#include <stdint.h>
#include "Sys_Def.h"

#define UPGRADE_CMD_BUF_SIZE        9
#define UPGRADE_BUF_SIZE            (1024)

typedef struct _UART_MSG_
{
    char MSG[4];
    uint32_t msgVal;
}UART_MSG;

typedef struct _UPGRADE_PACKET_
{
    uint32_t    curBlockIdx;
    uint32_t    totalBlocks;
    uint32_t    BlockSize;
    uint8_t     data[UPGRADE_BUF_SIZE];
    uint32_t    crc32;
}UPGRADE_PACKET;

#define MAX_RETRY_TIMES             3
#define UPGRADE_LOG                 LOG_PRINT

uint32_t TiDTV_ComputeCRC32Value(uint8_t* pData, int len);
int  UART_Upgrade_Check(uint32_t USARTx);
void UART_Upgrade_Process(uint32_t USARTx);
void UART_Upgrade_Verify(uint32_t USARTx);

void iap_load_app(uint32_t newappaddr);

#endif
